package worldcuptour.database;

import java.io.ByteArrayOutputStream;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;

public class DbAdapter {

	private SQLiteDatabase database;
	private DbHelper dbHelper;
	private String[] cityColumns = {DbHelper.ID_CITY, DbHelper.NOME_CITY};
	private String[] atractionColumns = {DbHelper.ID_ATRACTION, DbHelper.DESCRIPTION_ATRACTION, DbHelper.CITY, DbHelper.IMG,  DbHelper.ID_TYPE_ATRACTION};
	private String[] taColumns = {DbHelper.ID_TYPE_ATRACTION, DbHelper.DESCRIPTION};
	
	public DbAdapter(Context context) {          
		dbHelper = new DbHelper(context);
	}
	
	public void createAtraction(String descriptionAtraction, String city, String idTypeAtraction, Bitmap img) { 
        ContentValues values = new ContentValues(); 
        values.put(DbHelper.DESCRIPTION_ATRACTION, descriptionAtraction); 
        values.put(DbHelper.CITY, city); 
        values.put(DbHelper.ID_TYPE_ATRACTION, idTypeAtraction); 
        ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
        img.compress(Bitmap.CompressFormat.PNG, 100, baos); 
        byte[] photo = baos.toByteArray(); 
        values.put(DbHelper.IMG, photo); 
        long insertId = database.insert(DbHelper.DATABASE_TABLE_ATRACTION, null, values); 
        Cursor cursor = database.query(DbHelper.DATABASE_TABLE_ATRACTION, atractionColumns, DbHelper.ID_ATRACTION + " = " + insertId, null,null, null, null); 
        cursor.moveToFirst(); 
//    	return cursorToAtraction(cursor); 
	}
}
